import javax.swing.JPanel;

import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.Font;
/*information of the player's name his
 * token, and property
 * it's property buttons calls the customizePlayerPanelUi
 * as they can mortgage their own property*/
public class playerPanelUi extends JPanel {

	private JPanel[] jpanel;
	private JLabel[] moneyLbl, moneyLabel;
	private JLabel[] iconLbl, iconLabel, lblOwnedProperties;
	private JButton[][] btnProp;
	private Block[] bl;
	private int propSelected;
	public JTabbedPane tabbedPane;
	public Player[] p;
	private BoardUi board;
	
	public playerPanelUi(int totalNumOfPlayers, Player[] play, BoardUi board_, Block[] bl_) {
		setBackground(new Color(143, 188, 143));
		this.board=board_;
		jpanel = new JPanel[totalNumOfPlayers];
		moneyLbl = new JLabel[totalNumOfPlayers];
		moneyLabel = new JLabel[totalNumOfPlayers];
		iconLbl = new JLabel[totalNumOfPlayers];
		iconLabel = new JLabel[totalNumOfPlayers];
		lblOwnedProperties = new JLabel[totalNumOfPlayers];
		this.p = play;
		this.bl = bl_;
		
		this.btnProp= new JButton[8][40];
		
		setLayout(null);
		
		setTabbedPane(new JTabbedPane(JTabbedPane.TOP));
		getTabbedPane().setBounds(564, 176, 450, 350);
		add(getTabbedPane());
			
		showNumberOfTabs();
	}
	
	public void showNumberOfTabs(){
		board.contentPane.add(getTabbedPane());
		for(int i=0; i<this.jpanel.length; i++){
			jpanel[i] = new JPanel();
			getTabbedPane().addTab(this.p[i].getName(), null, jpanel[i], null);
			jpanel[i].setLayout(null);
			
			moneyLbl[i] = new JLabel("Money:");
			moneyLbl[i].setBounds(10, 14, 60, 14);
			moneyLbl[i].setFont(new Font("Tahoma", Font.BOLD, 14));
			jpanel[i].add(moneyLbl[i]);
			
			moneyLabel[i] = new JLabel(Integer.toString(this.p[i].getMoney()));
			moneyLabel[i].setBounds(70, 14, 46, 14);
			moneyLabel[i].setOpaque(true);
			jpanel[i].add(moneyLabel[i]);
			
			iconLbl[i] = new JLabel("Token:");
			iconLbl[i].setBounds(10, 31, 60, 14);
			iconLbl[i].setFont(new Font("Tahoma", Font.BOLD, 14));
			jpanel[i].add(iconLbl[i]);
			
			lblOwnedProperties[i] = new JLabel("OWNED PROPERTIES:");
			lblOwnedProperties[i].setOpaque(true);
			lblOwnedProperties[i].setFont(new Font("Tahoma", Font.BOLD, 14));
			lblOwnedProperties[i].setBounds(168, 59, 165, 14);
			jpanel[i].add(lblOwnedProperties[i]);
			
			iconLabel[i] = new JLabel(new ImageIcon(getClass().getResource(this.p[i].getIcon())));
			iconLabel[i].setBounds(70, 31, 46, 14);
			jpanel[i].add(iconLabel[i]);
	
			btnProp[i][1] = new JButton("");
			btnProp[i][1].setVisible(false);
			btnProp[i][1].setEnabled(false);
			btnProp[i][1].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Rizal.jpg")));
			btnProp[i][1].setBounds(62, 98, 45, 45);
			btnProp[i][1].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=1;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][1]);
			
			btnProp[i][3] = new JButton("");
			btnProp[i][3].setVisible(false);
			btnProp[i][3].setEnabled(false);
			btnProp[i][3].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/LapuLapu.jpg")));
			btnProp[i][3].setBounds(117, 98, 45, 45);
			btnProp[i][3].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=3;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][3]);
			
			btnProp[i][6] = new JButton("");
			btnProp[i][6].setVisible(false);
			btnProp[i][6].setEnabled(false);
			btnProp[i][6].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/8Waves.jpg")));
			btnProp[i][6].setBounds(172, 98, 45, 45);
			btnProp[i][6].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=6;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][6]);
			
			btnProp[i][8] = new JButton("");
			btnProp[i][8].setVisible(false);
			btnProp[i][8].setEnabled(false);
			btnProp[i][8].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Regency.jpg")));
			btnProp[i][8].setBounds(227, 98, 45, 45);
			btnProp[i][8].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=8;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][8]);
			
			btnProp[i][9] = new JButton("");
			btnProp[i][9].setVisible(false);
			btnProp[i][9].setEnabled(false);
			btnProp[i][9].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/SplashIsland.jpg")));
			btnProp[i][9].setBounds(282, 98, 45, 45);
			btnProp[i][9].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=9;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][9]);
			
			btnProp[i][5] = new JButton("");
			btnProp[i][5].setVisible(false);
			btnProp[i][5].setEnabled(false);
			btnProp[i][5].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/MRT1.jpg")));
			btnProp[i][5].setBounds(342, 98, 45, 45);
			btnProp[i][5].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=5;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][5]);
			
			btnProp[i][12] = new JButton("");
			btnProp[i][12].setVisible(false);
			btnProp[i][12].setEnabled(false);
			btnProp[i][12].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Meralco.jpg")));
			btnProp[i][12].setBounds(397, 155, 45, 45);
			btnProp[i][12].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=12;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][12]);
			
			btnProp[i][11] = new JButton("");
			btnProp[i][11].setVisible(false);
			btnProp[i][11].setEnabled(false);
			btnProp[i][11].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/dusit.jpg")));
			btnProp[i][11].setBounds(10, 155, 45, 45);
			btnProp[i][11].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=11;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][11]);
			
			btnProp[i][14] = new JButton("");
			btnProp[i][14].setVisible(false);
			btnProp[i][14].setEnabled(false);
			btnProp[i][14].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/shangrila.jpg")));
			btnProp[i][14].setBounds(62, 155, 45, 45);
			btnProp[i][14].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=14;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][14]);
			
			btnProp[i][13] = new JButton("");
			btnProp[i][13].setVisible(false);
			btnProp[i][13].setEnabled(false);
			btnProp[i][13].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/newWorld.jpg")));
			btnProp[i][13].setBounds(117, 155, 45, 45);
			btnProp[i][13].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=13;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][13]);
		
			btnProp[i][19] = new JButton("");
			btnProp[i][19].setVisible(false);
			btnProp[i][19].setEnabled(false);
			btnProp[i][19].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/sm.jpg")));
			btnProp[i][19].setBounds(172, 155, 45, 45);
			btnProp[i][19].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=19;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][19]);
			
			btnProp[i][16] = new JButton("");
			btnProp[i][16].setVisible(false);
			btnProp[i][16].setEnabled(false);
			btnProp[i][16].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/glorietta.jpg")));
			btnProp[i][16].setBounds(227, 155, 45, 45);
			btnProp[i][16].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=16;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][16]);
			
			btnProp[i][18] = new JButton("");
			btnProp[i][18].setVisible(false);
			btnProp[i][18].setEnabled(false);
			btnProp[i][18].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Moa.jpg")));
			btnProp[i][18].setBounds(282, 155, 45, 45);
			btnProp[i][18].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=18;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][18]);
			
			btnProp[i][15] = new JButton("");
			btnProp[i][15].setVisible(false);
			btnProp[i][15].setEnabled(false);
			btnProp[i][15].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/MRT2.jpg")));
			btnProp[i][15].setBounds(342, 155, 45, 45);
			btnProp[i][15].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=15;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][15]);
		
			btnProp[i][28] = new JButton("");
			btnProp[i][28].setVisible(false);
			btnProp[i][28].setEnabled(false);
			btnProp[i][28].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Maynilad.jpg")));
			btnProp[i][28].setBounds(397,210, 45, 45);
			btnProp[i][28].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=28;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][28]);
			
			btnProp[i][23] = new JButton("");
			btnProp[i][23].setVisible(false);
			btnProp[i][23].setEnabled(false);
			btnProp[i][23].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/OceanAdventure.jpg")));
			btnProp[i][23].setBounds(10, 210, 45, 45);
			btnProp[i][23].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=23;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][23]);
			
			btnProp[i][24] = new JButton("");
			btnProp[i][24].setVisible(false);
			btnProp[i][24].setEnabled(false);
			btnProp[i][24].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Zoobic.jpg")));
			btnProp[i][24].setBounds(62, 210, 45, 45);
			btnProp[i][24].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=24;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][24]);
			
			btnProp[i][21] = new JButton("");
			btnProp[i][21].setVisible(false);
			btnProp[i][21].setEnabled(false);
			btnProp[i][21].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Calatagan.jpg")));
			btnProp[i][21].setBounds(117, 210, 45, 45);
			btnProp[i][21].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=21;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][21]);
			
			btnProp[i][27] = new JButton("");
			btnProp[i][27].setVisible(false);
			btnProp[i][27].setEnabled(false);
			btnProp[i][27].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Sofitel.jpg")));
			btnProp[i][27].setBounds(172, 210, 45, 45);
			btnProp[i][27].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=27;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][27]);
			
			btnProp[i][26] = new JButton("");
			btnProp[i][26].setVisible(false);
			btnProp[i][26].setEnabled(false);
			btnProp[i][26].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/GreenBelt.jpg")));
			btnProp[i][26].setBounds(227, 210, 45, 45);
			btnProp[i][26].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=26;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][26]);
			
			btnProp[i][29] = new JButton("");
			btnProp[i][29].setVisible(false);
			btnProp[i][29].setEnabled(false);
			btnProp[i][29].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Trinoma.jpg")));
			btnProp[i][29].setBounds(282, 210, 45, 45);
			btnProp[i][29].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=29;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][29]);
		
			btnProp[i][34] = new JButton("");
			btnProp[i][34].setVisible(false);
			btnProp[i][34].setEnabled(false);
			btnProp[i][34].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/serendra.jpg")));
			btnProp[i][34].setBounds(62, 267, 45, 45);
			btnProp[i][34].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=34;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][34]);
			
			btnProp[i][32] = new JButton("");
			btnProp[i][32].setVisible(false);
			btnProp[i][32].setEnabled(false);
			btnProp[i][32].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/Robinsons.jpg")));
			btnProp[i][32].setBounds(117, 267, 45, 45);
			btnProp[i][32].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=32;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][32]);
			
			btnProp[i][31] = new JButton("");
			btnProp[i][31].setVisible(false);
			btnProp[i][31].setEnabled(false);
			btnProp[i][31].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/EastWoodMall.jpg")));
			btnProp[i][31].setBounds(172, 267, 45, 45);
			btnProp[i][31].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=31;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][31]);
			
			btnProp[i][37] = new JButton("");
			btnProp[i][37].setVisible(false);
			btnProp[i][37].setEnabled(false);
			btnProp[i][37].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/EnchantedKingdom.jpg")));
			btnProp[i][37].setBounds(227,267, 45, 45);
			btnProp[i][37].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=37;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][37]);
			
			btnProp[i][39] = new JButton("");
			btnProp[i][39].setVisible(false);
			btnProp[i][39].setEnabled(false);
			btnProp[i][39].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/StarCity.jpg")));
			btnProp[i][39].setBounds(282, 267, 45, 45);
			btnProp[i][39].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=39;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][39]);
			
			btnProp[i][25] = new JButton("");
			btnProp[i][25].setVisible(false);
			btnProp[i][25].setEnabled(false);
			btnProp[i][25].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/MRT3.jpg")));
			btnProp[i][25].setBounds(342, 210, 45, 45);
			btnProp[i][25].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=25;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][25]);
			
			btnProp[i][35] = new JButton("");
			btnProp[i][35].setVisible(false);
			btnProp[i][35].setEnabled(false);
			btnProp[i][35].setIcon(new ImageIcon(playerPanelUi.class.getResource("/smallPics/MRT4.jpg")));
			btnProp[i][35].setBounds(342, 267, 45, 45);
			btnProp[i][35].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					propSelected=35;
					showCustomizePropertyPanel();
				}
			});
			jpanel[i].add(btnProp[i][35]);
		}
	}
	
	public void updatePlayerMoney(){
		for(int i=0; i<this.jpanel.length; i++){		
		moneyLabel[i].setText(Integer.toString(this.p[i].getMoney()));
		}
	}
	
	public void setTabbedPane(JTabbedPane tabbedPane) {
		this.tabbedPane = tabbedPane;
	}

	public JTabbedPane getTabbedPane() {
		return tabbedPane;
	}
	
	public void updateButtons(int playNum, int btnNum){
		btnProp[playNum][btnNum].setVisible(true);
		btnProp[playNum][btnNum].setEnabled(true);
	}
	
	public void showCustomizePropertyPanel(){
		
		CustomizePropertyPanel customPropPanel = new CustomizePropertyPanel(bl[propSelected], this);
	
	}
}
